package com.rookie.data.generate.component;

import com.rookie.data.generate.component.generate.DateGenerate;
import com.rookie.data.generate.component.generate.NumberGenerate;
import com.rookie.data.generate.component.generate.StringGenerate;
import com.rookie.data.generate.constant.annotation.Extract;
import com.rookie.data.generate.constant.enums.ColumnRangeEnum;
import com.rookie.data.generate.model.project.FieldProperties;
import com.rookie.data.generate.model.project.TableColumnEntity;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;

@Component
public class BaseGenerate {

    public static Object generate(TableColumnEntity tableColumn, FieldProperties properties) {
        if (properties == null){
            properties = new FieldProperties();
        }
        String columnType = tableColumn.getDataType().toUpperCase();
        ColumnRangeEnum columnRangeEnum = ColumnRangeEnum.getNumberEnum(columnType);

        if (columnRangeEnum == null) {
            return null;
        }
        if (properties.getNullStatus() != null && properties.getNullStatus()) {
            return null;
        }
        if (properties.getAnnotations() != null){
            for (Annotation annotation : properties.getAnnotations()) {
                if (annotation != null) {
                    return BeanContainer.generateAnnotation.get(annotation.annotationType()).generate(tableColumn, annotation);
                }
            }
        }


        switch (columnRangeEnum.getType()) {
            case 1:
            case 2:
                return NumberGenerate.generate(tableColumn, properties, columnRangeEnum);
            case 3:
                return StringGenerate.generate(tableColumn, properties, columnRangeEnum);
            case 4:
                return DateGenerate.generate(tableColumn, properties, columnRangeEnum);
            default:
                return null;
        }
    }


}
